public class SqrtX {
    public int mySqrt(int x) {
        // 边界判断
        if(x < 1) {
            return 0;
        }

        // [小于等于x区间]   [大于x区间]
        long left = 1, right = x;
        while(left < right) {
            long mid = left + ((right - left + 1) >> 1);
            long target = mid * mid;
            if(target <= x) {
                left = mid;
            }else {
                right = mid - 1;
            }
        }

        return (int)left;
    }
}
